# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : sql注入.py
# @Author: dongguangwen
# @Date  : 2024-08-11 12:35
import pymysql

# 输入账号和密码
user = input('请输入用户名：')
password = input('请输入密码：')

conn = pymysql.connect(host='192.168.1.9', port=3306, user='root', password='root12345678', charset='utf8', db='new_database')
cursor = conn.cursor()

# 基于字符串格式化来拼接sql语句
sql = "select * from students where name='{}' and password='{}'".format(user, password)
print(sql)
cursor.execute(sql)

result = cursor.fetchone()
print(result)

cursor.close()
conn.close()

"""
请输入用户名：zhangsan
请输入密码：123
select * from students where name='zhangsan' and password='123'
(1, 'zhangsan', '123')
"""

"""
请输入用户名：' or 1=1 -- 
请输入密码：123456
select * from students where name='' or 1=1 -- ' and password='123456'
(1, 'zhangsan', '123')
"""